<template>
	<view class="current-activity">
		<view class="current-activity-header">
			<view class="activity-tag activity-tag-bargain">砍价</view>
			<text class="current-activity-title">{{ activityName }}</text>
		</view>
		
		<view class="activity-detail">
			<view class="bargain-info">
				<text class="bargain-lowest">最低可砍至¥{{ lowestPrice }}</text>
				<text class="bargain-count">已有{{ participantCount }}人参与砍价</text>
			</view>
			<view class="activity-countdown">
				<text class="countdown-label">距结束</text>
				<text class="countdown-time">{{ countdownTime }}</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref, computed, onMounted, onUnmounted } from 'vue';
	
	const props = defineProps({
		activityType: {
			type: String,
			default: 'bargain'
		},
		currentActivity: {
			type: Object,
			default: () => null
		}
	});
	
	// 砍价活动名称
	const activityName = computed(() => {
		if (props.currentActivity && props.currentActivity.name) {
			return props.currentActivity.name;
		}
		return '邀请好友砍价，最低减50元';
	});
	
	// 最低价格
	const lowestPrice = ref('39.9');
	
	// 参与人数
	const participantCount = ref(56);
	
	// 倒计时
	const countdownTime = ref('23:59:59');
	let timer = null;
	
	// 模拟倒计时
	const startCountdown = () => {
		// 实际项目中应该根据活动结束时间计算倒计时
		// 这里仅作为示例
		let hours = 23;
		let minutes = 59;
		let seconds = 59;
		
		timer = setInterval(() => {
			seconds--;
			if (seconds < 0) {
				seconds = 59;
				minutes--;
				if (minutes < 0) {
					minutes = 59;
					hours--;
					if (hours < 0) {
						clearInterval(timer);
						return;
					}
				}
			}
			countdownTime.value = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
		}, 1000);
	};
	
	onMounted(() => {
		startCountdown();
		
		// 模拟参与人数增加
		const participantTimer = setInterval(() => {
			participantCount.value += 1;
		}, 30000);
	});
	
	onUnmounted(() => {
		if (timer) {
			clearInterval(timer);
		}
	});
</script>

<style lang="scss" scoped>
.current-activity {
	margin-bottom: 15px;
	padding-bottom: 15px;
	border-bottom: 1px dashed #eee;

	.current-activity-header {
		display: flex;
		align-items: center;
		margin-bottom: 10px;

		.activity-tag {
			padding: 2px 6px;
			border-radius: 3px;
			font-size: 11px;
			color: white;
			margin-right: 8px;
			
			&.activity-tag-bargain {
				background-color: #5856d6;
			}
		}

		.current-activity-title {
			font-size: 14px;
			font-weight: bold;
			color: #333;
		}
	}

	.activity-detail {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 10px;

		.activity-countdown {
			display: flex;
			align-items: center;

			.countdown-label {
				font-size: 12px;
				color: #666;
				margin-right: 5px;
			}

			.countdown-time {
				font-size: 14px;
				color: #ff3b30;
				font-weight: bold;
			}
		}
	}

	.bargain-info {
		.bargain-lowest {
			font-size: 14px;
			color: #ff6a6a;
			font-weight: bold;
			display: block;
			margin-bottom: 5px;
		}

		.bargain-count {
			font-size: 12px;
			color: #666;
		}
	}
}
</style>